Xbasic

a5SQLConnectionOpen Function

Syntax

Result_Flag as L = a5SQLConnectionOpen(cn as SQL::Connection, connString as C, session as P)

Arguments

Result_Flag

TRUE (.T.) if the operation was successful; otherwise FALSE (.F.)

cn

A SQL::Connection object.

connString

The name of the dynamic connection string to use. The dynamic connection string used must be defined in the session object.

session

The session object.

Description

Opens a connection to a database. This method supports using dynamic connection syntax.

Discussion

The a5SQLConnectionOpen() function can be used to open a connection to a SQL database. If the connection string uses the dynamic connection syntax, it will correctly resolve the correct connection string to use.

Take, for instance, the "standard" way of opening a connection:

dim cs as c 
cs = ":name::myconnstring"
dim cn as sql::connection
dim flag as l 
flag = cn.open(cs)

This can be rewritten using a dynamic connection using the a5SQLConnectionOpen() function as follows:

'using the a5SQLConnectionOpen() function
'assume that some prior code has set this session variable
session.__protected__conn1 = "::name::myOtherConnectionString"

dim cs as c 
cs = "::name::DynamicConnection_conn1"
dim cn as sql::connection
flag = a5SQLConnectionOpen(cn,cs,session)

Since the connection string you are trying to open is a dynamic connection (because the connection string name starts with 'DynamicConnection') the actual connection string that will be opened is the connection string specified by session.__protected__conn1.

This connection string is ::name::myOtherConnectionString. So the connection opened by this function will be ::name::myOtherConnectionString.

See Also